﻿using DAL.DataTransferObject;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace DAL.DataAccessObject
{
    public class NhanVienDAO:DataProvider.DataAccess
    {
        public void InsertNhanVien(NhanVien nv )
        {
            SqlCommand cmd = new SqlCommand("insert into NhanVien set" +
            "MaNV=@manv, TenNV=@tenNV, HoDemNV=@HoDemNV," +
            "NgaySinh=@NS, GT=@GT, DiaChi=@DC,SDT=@SDT,Luong=@Luong" +
            "NgayLamViec@NLV,ChucVu=@ChucVu,MaNQL=@NQL", GetConnection());
            //cmd.Parameters.Add(new SqlParameter("@",SqlDbType.));
            //cmd.Parameters.Add(new SqlParameter("@",SqlDbType.));
            //cmd.Parameters.Add(new SqlParameter("@",SqlDbType.));
            //cmd.Parameters.Add(new SqlParameter("@",SqlDbType.));
            //cmd.Parameters.Add(new SqlParameter("@",SqlDbType.));
            //cmd.Parameters.Add(new SqlParameter("@",SqlDbType.));
            //cmd.Parameters.Add(new SqlParameter("@",SqlDbType.));
            //cmd.Parameters.Add(new SqlParameter("@",SqlDbType.));
            //cmd.Parameters.Add(new SqlParameter("@",SqlDbType.));
            //cmd.Parameters.Add(new SqlParameter("@",SqlDbType.));
            //cmd.Parameters.Add(new SqlParameter("@",SqlDbType.));

        }

        public void UpdateNhanVien(NhanVien nv)
        {
            SqlCommand cmd = new SqlCommand("insert into NhanVien set" +
            "MaNV=@manv, TenNV=@tenNV, HoDemNV=@HoDemNV," +
            "NgaySinh=@NS, GT=@GT, DiaChi=@DC,SDT=@SDT,Luong=@Luong" +
            "NgayLamViec@NLV,ChucVu=@ChucVu,MaNQL=@NQL", GetConnection());
        }

        public void DeleteNhanVien(NhanVien nv)
        {

        }

        public List<NhanVien> GetListNhanVien()
        {
            List<NhanVien> list=new List<NhanVien>();
            DataTable dt = this.SelectAllNhanVien();
            NhanVien nv;
            for(int i=0;i<dt.Rows.Count;i++)
            {
                nv = new NhanVien();
                nv.maNV = dt.Rows[i]["MaNV"].ToString();
                nv.tenNV= dt.Rows[i]["TenNV"].ToString();
                nv.hoDemNV= dt.Rows[i]["HoDemNV"].ToString();
                if (dt.Rows[i]["NgaySinh"].ToString().Length>0)
                nv.ngaySinh= Convert.ToDateTime(dt.Rows[i]["NgaySinh"].ToString());
                if (dt.Rows[i]["NgayLamViec"].ToString().Length>0)
                nv.ngayLamViec= Convert.ToDateTime(dt.Rows[i]["NgayLamViec"].ToString());
                nv.SDT= dt.Rows[i]["SDT"].ToString();
                nv.GT= dt.Rows[i]["GT"].ToString();
                nv.diaChi= dt.Rows[i]["DiaChi"].ToString();
                nv.chucVu= dt.Rows[i]["ChucVu"].ToString();
                nv._luong= Convert.ToInt32(dt.Rows[i]["Luong"].ToString());
                nv.maNQL= dt.Rows[i]["MaNQL"].ToString();
                list.Add(nv);
            }
            return list;
        }

        public DataTable SelectAllNhanVien()
        {
            SqlCommand cmd = new SqlCommand("select * from NhanVien", GetConnection());
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt;
        }
    }
}
